package com.jk.smartelderlycare.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jk.smartelderlycare.dao.SysSliderMapper;
import com.jk.smartelderlycare.dto.SysSign;
import com.jk.smartelderlycare.dto.SysSlider;
import com.jk.smartelderlycare.pojo.PagedResponse;
import com.jk.smartelderlycare.service.SysSliderService;
import com.jk.smartelderlycare.utils.PaginationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author hhk
 * @version 1.0
 * @ClassName SysSliderServiceImpl
 * @program: smart-elderly-care
 * @description: TODO
 * @date 2024/11/19 17:20
 */
@Service
public class SysSliderServiceImpl implements SysSliderService {

    @Autowired
    private SysSliderMapper sysSliderMapper;
    /**
     * @description: 后端分页查询
     * @param: [sysSign, pageNum, pageSize]
     * @return: com.jk.smartelderlycare.pojo.PagedResponse<com.jk.smartelderlycare.dto.SysSlider>
     * @author hhk
     * @date: 2024/11/19 17:20
     */
    @Override
    public PagedResponse<SysSlider> findSysSliderPaginationList(SysSlider sysSlider, Integer pageNum, Integer pageSize) {

        Page<SysSlider> page = new Page<>(pageNum,pageSize);
        IPage<SysSlider> sysSliderIPage = sysSliderMapper.findSysSliderPaginationList(sysSlider,page);
        return PaginationUtil.getPagedResponse(sysSliderIPage.getRecords(),pageNum,pageSize,sysSliderIPage.getTotal());

//        Page<SysSlider> page = new Page<>(pageNum, pageSize);
//        QueryWrapper<SysSlider> queryWrapper = new QueryWrapper<>();
        //条查
//        if (null != sysSlider.getSliderTitle() && "".equals(sysSlider.getSliderTitle())) {
//            queryWrapper.like("slider_title", sysSlider.getSliderTitle());
//        }
        //排序倒排
//        queryWrapper.orderByDesc("slider_num") ;
//        Page<SysSlider> sysSliderList = sysSliderMapper.selectPage(page, queryWrapper);
//        return PaginationUtil.getPagedResponse(sysSliderList.getRecords() ,pageNum,pageSize,sysSliderList.getTotal()) ;


    }
    /**
     * @description: 新增轮播图
     * @param: [sysSlider]
     * @return: void
     * @author hhk
     * @date: 2024/11/19 17:20
     */
    @Override
    public void addSlider(SysSlider sysSlider) {
        sysSliderMapper.insert(sysSlider);
    }
    /**
     * @description: 根据id删除一条数据
     * @param: [sliderId]
     * @return: void
     * @author hhk
     * @date: 2024/11/19 17:22
     */
    @Override
    public void deleteSysSliderById(Long sliderId) {
        sysSliderMapper.deleteById(sliderId);
    }
    /**
     * @description: 根据id回显一条数据
     * @param: [sliderId]
     * @return: com.jk.smartelderlycare.dto.SysSlider
     * @author hhk
     * @date: 2024/11/19 17:22
     */
    @Override
    public SysSlider findSysSliderById(Long sliderId) {
        return sysSliderMapper.selectById(sliderId);
    }
    /**
     * @description: 修改轮播图
     * @param: [sysSlider]
     * @return: void
     * @author hhk
     * @date: 2024/11/19 17:22
     */
    @Override
    public void updateSysSlider(SysSlider sysSlider) {
        sysSliderMapper.updateById(sysSlider);
    }
    /**
     * @description: 状态修改
     * @param: [sysSlider]
     * @return: void
     * @author hhk
     * @date: 2024/11/19 17:23
     */
    @Override
    public void updataStutas(SysSlider sysSlider) {
        sysSliderMapper.updataStutas(sysSlider);
    }
    /**
     * @description: 批量删除
     * @param: [sliderId]
     * @return: void
     * @author hhk
     * @date: 2024/11/19 19:22
     */
    @Override
    public void deleteSysSliderByIds(List<Long> ids) {
        sysSliderMapper.deleteBatchIds(ids);
    }
}
